package com.itheima.test5;

import java.util.Scanner;

public class CarTest {

    public static void main(String[] args) {
        // 定义数组
        Car[] arr = new Car[3];

        // 创建商品，数据来源于键盘录入
        Scanner sc = new Scanner(System.in);


        for (int i = 0; i < arr.length; i++) {
            Car car = new Car();//未知参数  使用空参构造方法
            System.out.println("请输入第" + (i + 1) + "辆车的品牌:");
            String brand = sc.next();
            car.setBrand(brand);

            System.out.println("请输入第" + (i + 1) + "辆车的价格:");
            int price = sc.nextInt();
            car.setPrice(price);

            System.out.println("请输入第" + (i + 1) + "辆车的颜色:");
            String color = sc.next();
            car.setColor(color);

            //保存数据
            arr[i] = car;

        }

        //打印数据
        for (int i = 0; i < arr.length; i++) {
            Car car = arr[i];
            System.out.println("第"+ (i + 1)  + "辆车的信息:" + car.getBrand() + " " + car.getPrice() + " " + car.getColor());
        }

    }


}
